package com.hee.erp.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hee.erp.modules.entity.CarInsure;
import com.hee.erp.modules.entity.SysUserContract;
import com.hee.erp.modules.mapper.CarInsureMapper;
import com.hee.erp.modules.service.ICarInsureService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hee.erp.vo.CarInsureListProperty;
import com.hee.erp.vo.UserContractListProperty;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author weizehong
 * @since 2022-05-02
 */
@Service
@Transactional
public class CarInsureServiceImpl extends ServiceImpl<CarInsureMapper, CarInsure> implements ICarInsureService {


    @Override
    public List<CarInsure> listByCarId(String carId) {
        LambdaQueryWrapper<CarInsure> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CarInsure::getCarId, carId);
        wrapper.orderByDesc(CarInsure::getYears);
        List<CarInsure> list = list(wrapper);

        if(list.size() == 0){
            CarInsure carInsure = new CarInsure();
            carInsure.setYears(LocalDate.now().getYear() + "年");

            list.add(carInsure);
        }
        return list;
    }
}
